// utils/websocket/router.js

import inviteHandler from './handlers/invite';
import privateHandler from './handlers/private';
import groupHandler from './handlers/group';
import addFriendHandler from './handlers/addFriend';

import { MESSAGE_TYPES } from './messageTypes';

const handlers = {
  [MESSAGE_TYPES.PRIVATE]: privateHandler,
  [MESSAGE_TYPES.GROUP]: groupHandler,
  [MESSAGE_TYPES.INVITE]: inviteHandler,
  [MESSAGE_TYPES.ADD_FRIEND]: addFriendHandler
};

export default function routeWebSocketMessage(message) {
  const type = message.messageType;

  const handler = handlers[type];
  if (handler) {
    handler(message);
  } else {
    console.warn('未定义的消息类型:', type, message);
  }
}